
import { request } from '@umijs/max';
import { PageResponse } from '.';


export interface MessageBoardInfo {
  id: number;
  createdBy: number;
  content: string;
  username: string;
  likeCount: number;
  time: string;
  famousPersonId: number;
  userAvatar: string;
  isLike: boolean;
  // 是否是当前用户
  isCurrentUser: boolean;
}

// 发表留言
export const publishMessageBoard = (data: any) => {
  return request<MessageBoardInfo>(`/messages_board`, {
    method: 'POST',
    data
  });
};

// 点赞
export const likeMessageBoard = (id: number) => {
  return request<boolean>(`/messages_board/like/${id}`, {
    method: 'POST'
  });
};

// 分页获取留言列表
export const getMessageBoardList = (data: any) => {
  return request<PageResponse<MessageBoardInfo>>(`/messages_board/page`, {
    method: 'POST',
    data
  });
};

// 删除留言
export const deleteMessageBoard = (id: number) => {
  return request(`/messages_board/${id}`, {
    method: 'DELETE'
  });
};

// 修改留言
export const updateMessageBoard = (data: any) => {
  return request<MessageBoardInfo>(`/messages_board`, {
    method: 'PUT',
    data
  });
};

// 取消点赞
export const unlikeMessageBoard = (id: number) => {
  return request<boolean>(`/messages_board/unlike/${id}`, {
    method: 'POST'
  });
};

